﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AWA.VAT.EmailApp.Controllers;

namespace AWA.VAT.EmailApp
{
    public partial class EmailForm : Form
    {
        private VATEmailController _controller;

        public bool SendEnabled { get; set; }

        public EmailForm(VATEmailController controller)
        {
            InitializeComponent();
            this._controller = controller;
            SendEnabled = true;
            EnableSendButton();  // TODO: move to controller
        }

        public string Message
        {
            get { return lblMessage.Text; }
            set { lblMessage.Text = value; }
        }

        public string Username
        {
            get { return txtUsername.Text; }
        }

        public string Password
        {
            get { return txtPassword.Text; }
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            _controller.Send();
        }

        private void HandleUsernamePasswordTextChanged(object sender, EventArgs e)
        {
            EnableSendButton(); // TODO: move to controller
        }

        private void HandleOpenSpreadsheet(object sender, EventArgs e)
        {
            _controller.OpenSpreadsheet();
            EnableSendButton();  // TODO: move to controller
        }

        private void EnableSendButton()
        {
            // TODO: move to controller
            bool enable = !String.IsNullOrEmpty(txtUsername.Text) &&
                !String.IsNullOrEmpty(txtPassword.Text) &&
                !String.IsNullOrEmpty(Configuration.FileLocation) &&
                SendEnabled;
            btnSend.Enabled = enable;
        }
    }
}
